from selenium.webdriver.common.by import By


def get_select_value(loc, num):
    return By.XPATH, loc[:loc.rfind('[') + 1] + f'{num}]'


def set_true_false(addr, mark):
    if mark:
        loc = get_select_value(addr, 2)
    else:
        loc = get_select_value(addr, 1)
    return loc


"""网站管理主菜单"""
web_manager_menu = By.XPATH, '//*[@id="admin-offcanvas"]/div/ul/li[8]/a'

"""子菜单——导航管理"""
navigation_manager = By.XPATH, '//*[@id="power-menu-222"]/li[1]/a'
# 进入iframe界面
iframe = By.XPATH, '//*[@id="ifcontent"]'
# 中间导航
navigation_centre_navigation = By.PARTIAL_LINK_TEXT, '中间导航'
# 底部导航
navigation_bottom_navigation = By.PARTIAL_LINK_TEXT, '底部导航'
""" 新增 """
# 新增按钮
navigation_add_butt = By.XPATH, '/html/body/div[2]/div/form/div[2]/div/button'
# 自定义导航添加
navigation_add_custom = By.XPATH, '/html/body/div[2]/div/form/div[2]/div/ul/li[1]/button'
""" 由于所有的添加的提示信息使用的元素是同一个，所以这个元素定位可以公用 """
# 提交提示
add_save_info = By.XPATH, '//*[@id="common-prompt"]/p'
# //*[@id="common-prompt"]/p  、 //*[@id="common-prompt"]/p
""" 自定义导航添加的内容元素定位 """
# 保存按钮
add_custom_save_butt = By.XPATH, '//*[@id="nav-custom-save-win"]/div/div[2]/form/div[7]/button'
# 提交出错的返回按钮
add_custom_error_back = By.XPATH, '//*[@id="nav-custom-save-win"]/div/div[1]/span'
# 导航级别
select_custom_rank = By.XPATH, '//*[@id="nav-custom-save-win"]/div/div[2]/form/div[1]/div/a/span'


def custom_rank(num):
    return get_select_value('//*[@id="nav-custom-save-win"]/div/div[2]/form/div[1]/div/div/ul/li[1]', num)


# 导航名称
input_custom_name = By.XPATH, '//*[@id="nav-custom-save-win"]/div/div[2]/form/div[2]/input'
# url地址
input_custom_url = By.XPATH, '//*[@id="nav-custom-save-win"]/div/div[2]/form/div[3]/input'
# 顺序
input_custom_sequence = By.XPATH, '//*[@id="nav-custom-save-win"]/div/div[2]/form/div[4]/input'


# 显示/不显示
def custom_radio_show(mark):
    return set_true_false('//*[@id="nav-custom-save-win"]/div/div[2]/form/div[5]/div/label[2]', mark)


# 是否新窗口打开
def custom_view_new(mark):
    return set_true_false('//*[@id="nav-custom-save-win"]/div/div[2]/form/div[6]/div/label[2]', mark)


# 文章导航添加
navigation_add_article = By.XPATH, '/html/body/div[2]/div/form/div[2]/div/ul/li[2]/button'
""" 文章导航添加元素定位 """
# 保存按钮
add_article_save_butt = By.XPATH, '//*[@id="nav-article-save-win"]/div/div[2]/form/div[7]/button'
# 提交出错的返回按钮
add_article_error_back = By.XPATH, '//*[@id="nav-article-save-win"]/div/div[1]/span'
# 导航级别
select_article_rank = By.XPATH, '//*[@id="nav-article-save-win"]/div/div[2]/form/div[1]/div/a'


def article_rank(num):
    return get_select_value('//*[@id="nav-article-save-win"]/div/div[2]/form/div[1]/div/div/ul/li[1]', num)


# 文章
select_article_choose = By.XPATH, '//*[@id="nav-article-save-win"]/div/div[2]/form/div[2]/div/a'


def article_choose(num):
    return get_select_value('//*[@id="nav-article-save-win"]/div/div[2]/form/div[2]/div/div/ul/li[3]', num)


# 导航名称
input_article_name = By.XPATH, '//*[@id="nav-article-save-win"]/div/div[2]/form/div[3]/input'
# 顺序
input_article_sequence = By.XPATH, '//*[@id="nav-article-save-win"]/div/div[2]/form/div[4]/input'


# 是否显示
def article_show(mark):
    return set_true_false('//*[@id="nav-article-save-win"]/div/div[2]/form/div[5]/div/label[1]', mark)


# 是否新窗口打开
def article_view_new(mark):
    return set_true_false('//*[@id="nav-article-save-win"]/div/div[2]/form/div[6]/div/label[2]', mark)


# 自定义页面导航添加
navigation_add_custom_page = By.XPATH, '/html/body/div[2]/div/form/div[2]/div/ul/li[3]/button'
""" 自定义页面导航增加的元素定位 """
# 导航级别
select_custom_page_rank = By.XPATH, '//*[@id="nav-customview-save-win"]/div/div[2]/form/div[1]/div/a'


def custom_page_rank(num):
    return get_select_value('//*[@id="nav-customview-save-win"]/div/div[2]/form/div[1]/div/div/ul/li[1]', num)


# 自定义页面
select_custom_page_view = By.XPATH, '//*[@id="nav-customview-save-win"]/div/div[2]/form/div[2]/div/a'


def custom_page_view(num):
    return get_select_value('//*[@id="nav-customview-save-win"]/div/div[2]/form/div[2]/div/div/ul/li[1]', num)


# 导航名称
input_custom_page_name = By.XPATH, '//*[@id="nav-customview-save-win"]/div/div[2]/form/div[3]/input'
# 顺序
input_custom_page_sequence = By.XPATH, '//*[@id="nav-customview-save-win"]/div/div[2]/form/div[4]/input'


# 是否显示
def custom_page_show(mark):
    return set_true_false('//*[@id="nav-customview-save-win"]/div/div[2]/form/div[5]/div/label[2]', mark)


# 是否新窗口打开
def custom_page_view_new(mark):
    return set_true_false('//*[@id="nav-customview-save-win"]/div/div[2]/form/div[6]/div/label[2]', mark)


# 商品分类
navigation_add_commodity = By.XPATH, '/html/body/div[2]/div/form/div[2]/div/ul/li[4]/button'
""" 删除 """
# 删除按钮
navigation_delete_butt = By.XPATH, '/html/body/div[2]/div/form/div[2]/button[1]'
""" 因为显示的数据为表格形式，所以通过tbody找到tr，再找td中的勾选框 """


# 获取第几个——tr,num为选取第几个tr
def select_tbody_tr(num):
    return get_select_value('/html/body/div[2]/div/form/div[3]/table/tbody/tr[1]', num)


# 获取tr中，td下的div下的label元素
def select_tbody_tr_td(num):
    addr = select_tbody_tr(num)
    return addr[0], addr[1] + '/td[1]/div/label'


# 确认删除按钮，因为span元素的父级元素的id是随机的，所以通过css选择器，获取span
navigation_delete_true = By.CSS_SELECTOR, 'div.am-modal-footer > span:nth-child(2)'

""" 搜索 """
# 搜索按钮
navigation_search_butt = By.XPATH, '/html/body/div[2]/div/form/div[2]/button[2]'
# 重置搜索的链接
navigation_reset_a = By.XPATH, '/html/body/div[2]/div/form/div[2]/a'

"""子菜单——自定义界面"""

"""子菜单——友情链接"""

"""子菜单——主题管理"""

"""子菜单——首页轮播"""

"""子菜单——筛选价格"""

"""子菜单——地区管理"""
address_manager = By.XPATH, '//*[@id="power-menu-222"]/li[7]/a'
# 新增按钮
address_add_butt = By.XPATH, '/html/body/div[2]/div/div[1]/button'
# 新增——名称输入框
input_address_add_district = By.XPATH, '//*[@id="data-save-win"]/div/div[2]/form/div[1]/input'
# 新增——顺序输入框
input_address_add_sequence = By.XPATH, '//*[@id="data-save-win"]/div/div[2]/form/div[2]/input'


# 新增——是否启用单选框
def radio_address_add_use(mark):
    return set_true_false('//*[@id="data-save-win"]/div/div[2]/form/div[3]/div/label[2]', mark)


# 新增——保存按钮
address_add_save_butt = By.XPATH, '//*[@id="data-save-win"]/div/div[2]/form/div[4]/button'


# table中的tr
def address_add_tbody_tr(num):
    return get_select_value('/html/body/div[2]/div/div[3]/table/tbody/tr[1]', num)


# 新增——行内——更多按钮
def address_add_tr_more_butt(num):
    result = address_add_tbody_tr(num)
    return result[0], result[1] + '/td/i'
    # //*[@id="data-list-1"]/td/div/button[2]


# 新增——行内——新增按钮
def address_add_tr_add_butt(num):
    result = address_add_tbody_tr(num)
    return result[0], result[1] + '/td/div/button[1]'


# 新增——行内——编辑按钮
def address_add_tr_edit_butt(num):
    result = address_add_tbody_tr(num)
    return result[0], result[1] + '/td/div/button[2]'


# 新增——行内——删除按钮
def address_add_tr_delete_butt(num):
    result = address_add_tbody_tr(num)
    return result[0], result[1] + '/td/div/button[3]'


"""子菜单——快递管理"""
express_manager = By.XPATH, '//*[@id="power-menu-222"]/li[8]/a'
# 新增按钮
express_add_butt = By.XPATH, '/html/body/div[2]/div/div[1]/button'
# 新增——名称输入框
input_express_add_district = By.XPATH, '//*[@id="data-save-win"]/div/div[2]/form/div[2]/input'
# 新增——顺序输入框
input_express_add_sequence = By.XPATH, '//*[@id="data-save-win"]/div/div[2]/form/div[3]/input'


# 新增——是否启用单选框
def radio_express_add_use(mark):
    return set_true_false('//*[@id="data-save-win"]/div/div[2]/form/div[4]/div/label[1]', mark)


# 新增——保存按钮
express_add_save_butt = By.XPATH, '//*[@id="data-save-win"]/div/div[2]/form/div[5]/button'


# table中的tr
def express_add_tbody_tr(num):
    return get_select_value('/html/body/div[2]/div/div[3]/table/tbody/tr[1]', num)


# 新增——行内——编辑按钮
def express_tr_edit_butt(num):
    result = address_add_tbody_tr(num)
    return result[0], result[1] + '/td/div/button[1]'


# 新增——行内——删除按钮
def express_tr_delete_butt(num):
    result = address_add_tbody_tr(num)
    return result[0], result[1] + '/td/div/button[2]'


# 删除确认按钮
express_delete_true = By.CSS_SELECTOR, 'div.am-modal-footer > span:nth-child(2)'


"""子菜单——支付方式"""
